//#include "BQ769XX.h"
//#include "delay.h"
//#include "24Cxx.h"
//#include "stdio.h"
//#include "drv_pin.h"
//#include "drv_soft_iic.h"
//#include <string.h>
//#include <stdlib.h>
//#include "main.h"
//#include "delay.h"
//#include "systemdata.h"
//#include "drv_timer.h"

//static void bq769xx_write_reg(BQ_Side bqSide,uint8_t WriteAddr,uint8_t DataToWrite);
//static Drv_I2c_Bus bq_iic_bus[2];
//static int8_t bq_iic_index[2] = {0};
//static Bq769x0CaliInfo bq_cali_info;
//static uint8_t oc_cur_table[16] = {17,22,28,33,39,44,50,56,61,67,72,78,83,89,94,100};
//static uint16_t oc_delay_table[8] = {8,20,40,80,160,320,640,1280};
//static uint16_t sc_cur_table[8] = {44,67,89,111,133,155,178,200};
//static uint16_t sc_delay_table[4] = {70,100,200,400};

//static uint16_t initial_gain_down = 0;
//static uint16_t initial_gain_up = 0;
//static uint8_t initial_offset_down = 0;
//static uint8_t initial_offset_up = 0;
//static bool gain_flag = false;
//static bool offset_flag = false;

//static BQ_MAKEUP_MODE bq_makeup_mode = bq76930_two;
//static BQ_SYS_CTRL_REG_STATUS bq_status;
//static uint8_t pre_charge_state = 0;
//static uint8_t charge_li_state = 0;
//static uint8_t bq_irq_flag = 0;//
//#define CURDIVIDERRES  0.5

//static const  uint8_t  crc8_Array[]={
//	0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, 
//	0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, 
//	0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, 
//	0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xb3, 0xBA, 0xbD, 
//	0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, 
//	0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A, 
//	0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A, 
//	0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, 
//	0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4, 
//	0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4, 
//	0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
//	0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34, 
//	0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63, 
//	0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, 
//	0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83, 
//	0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
//};

//static uint8_t cal_crc(uint8_t *vptr, uint8_t len){
//	uint16_t crc = 0;
//	uint8_t i, j;
//	for (j=0;j<len;j++) {
//		crc ^= (vptr[j] << 8);
//		for (i = 8; i; i--) {
//			if (crc & 0x8000){
//				crc ^= (0x1070 << 3);
//			}
//			crc <<= 1;
//		}
//	}
//	return (uint8_t)(crc >> 8);
//}

//uint8_t get_bq_makeup_mode(void){
//	return bq_makeup_mode;
//}

//uint8_t bq769xx_read_reg(BQ_Side bqSide,uint8_t ReadAddr){				  
//	uint8_t temp=0;
//	uint8_t crctemp=0;
//	uint8_t crc_buf[2];
//	bq_iic_bus[bqSide].start(bq_iic_index[bqSide]);  
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],0x10);  
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],ReadAddr); 
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	bq_iic_bus[bqSide].start(bq_iic_index[bqSide]);	 	   
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],0X10|0x01);		   
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	temp=bq_iic_bus[bqSide].read_byte(bq_iic_index[bqSide],1);
//	crctemp=bq_iic_bus[bqSide].read_byte(bq_iic_index[bqSide],0);
//	bq_iic_bus[bqSide].stop(bq_iic_index[bqSide]);                                                                                                                       
//	crc_buf[0]=0x11;
//	crc_buf[1]=temp;
//	if(cal_crc(crc_buf,2)==crctemp){
//		return temp;
//	}else{
//		return 0x00;
//	}
//}

//static uint8_t bq769xx_read_regs(BQ_Side bqSide,uint8_t ReadAddr,uint8_t *databuf,uint8_t len){		
//	uint8_t i=0;
//	uint8_t res=0;
//	uint8_t temp=0;
//	uint8_t crctemp=0;
//	uint8_t crc_buf[2];
//	uint8_t crc_res=0;
//	bq_iic_bus[bqSide].start(bq_iic_index[bqSide]);  
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],0x10);  
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],ReadAddr); 
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	bq_iic_bus[bqSide].start(bq_iic_index[bqSide]);		 	   
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],0X10|0x01);			   
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	temp=bq_iic_bus[bqSide].read_byte(bq_iic_index[bqSide],1);
//	crctemp=bq_iic_bus[bqSide].read_byte(bq_iic_index[bqSide],1);
//	crc_buf[0]=0x11;
//	crc_buf[1]=temp;
//	crc_res = cal_crc(crc_buf,2);
//	if(crc_res==crctemp){
//		databuf[0]=temp;
//		for(i=0;i<len-2;i++){
//			temp=bq_iic_bus[bqSide].read_byte(bq_iic_index[bqSide],1);
//			crctemp=bq_iic_bus[bqSide].read_byte(bq_iic_index[bqSide],1);
//			crc_res =  cal_crc(&temp,1);
//			if(crc_res==crctemp){ 
//				databuf[1+i]=temp; 
//			}else {
//				printf("Bq crc check error 1!\n");
//				return 2;
//			}
//		}
//		if(res==0){
//			temp=bq_iic_bus[bqSide].read_byte(bq_iic_index[bqSide],1);
//			crctemp=bq_iic_bus[bqSide].read_byte(bq_iic_index[bqSide],0);
//			crc_res =  cal_crc(&temp,1); 
//			if(crc_res==crctemp){
//				databuf[1+i]=temp; 
//			}else{
//				printf("Bq crc check error 2!\n");
//				return 2;
//			}
//		} 
//	}else{
//		printf("Bq crc check error 3!\n");
//		return 1;
//	} 
//	bq_iic_bus[bqSide].stop(bq_iic_index[bqSide]);
//	return res;
//}

//static void bq769xx_write_reg(BQ_Side bqSide,uint8_t WriteAddr,uint8_t DataToWrite){	
//	uint8_t crc_buf[3];
//	uint8_t crc_res=0;
//	bq_iic_bus[bqSide].start(bq_iic_index[bqSide]);  
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],0x10);  
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],WriteAddr); 
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],DataToWrite); 	
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	crc_buf[0]=0x10;
//	crc_buf[1]=WriteAddr;
//	crc_buf[2]=DataToWrite;
//	crc_res = cal_crc(crc_buf,3); 
//	bq_iic_bus[bqSide].send_byte(bq_iic_index[bqSide],crc_res); 	
//	bq_iic_bus[bqSide].wait_ask(bq_iic_index[bqSide]);
//	bq_iic_bus[bqSide].stop(bq_iic_index[bqSide]);
//	Delay_us(100);	 
//}

//static void bq769x0_alert_callback(void){
//	bq_irq_flag = 1;
//}

//uint8_t get_bq_irq_state(void){
//	uint8_t res = bq_irq_flag;
//	bq_irq_flag = 0;
//	
//	return res;
//}

//void bq_irq_timeout_deal(void){
//	bq769xx_write_reg(BQ_DOWN, CC_CFG,0x19);
//	//bq769xx_write_reg(BQ_DOWN, SYS_CTRL2,0x40);
//	bq769xx_write_reg(BQ_DOWN, SYS_STAT,0x80);
//}

//void bq_wake_ctrl(void){
//	hc32_pin_write(BQ_WAKE_PIN,PIN_LOW);
//	Delay_ms(20);
//	hc32_pin_write(BQ_WAKE_PIN,PIN_HIGH);
//	Delay_ms(20);
//	hc32_pin_write(BQ_WAKE_PIN,PIN_LOW);
//	Delay_ms(20);
//	hc32_pin_write(BQ_WAKE_PIN,PIN_HIGH);
//	Delay_ms(20);
//	hc32_pin_write(BQ_WAKE_PIN,PIN_LOW);
//}

//void destory_i2c(void){
//	drv_i2c_destory(&bq_iic_bus[BQ_DOWN]);
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		drv_i2c_destory(&bq_iic_bus[BQ_UP]);
//	}
//}

//void bq769x0_sleep_enter(void){
//	hc32_pin_mode(DOWN_BQ_SCL_PIN,PIN_MODE_OUTPUT);
//	hc32_pin_mode(DOWN_BQ_SDA_PIN,PIN_MODE_OUTPUT);
//	hc32_pin_write(DOWN_BQ_SCL_PIN,PIN_HIGH);
//	hc32_pin_write(DOWN_BQ_SDA_PIN,PIN_HIGH);
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		hc32_pin_mode(UP_BQ_SCL_PIN,PIN_MODE_OUTPUT);
//		hc32_pin_mode(UP_BQ_SDA_PIN,PIN_MODE_OUTPUT);
//		hc32_pin_write(UP_BQ_SCL_PIN,PIN_LOW);
//		hc32_pin_write(UP_BQ_SDA_PIN,PIN_LOW);
//	}		
//	hc32_pin_irq_enable(BQ_ALERT_PIN, PIN_IRQ_DISABLE);
//	hc32_pin_mode(BQ_ALERT_PIN,PIN_MODE_OUTPUT_OD);
//}

//void bq769x0_sleep_exit(void){
//	hc32_pin_mode(DOWN_BQ_SCL_PIN,PIN_MODE_OUTPUT_PULLUP);
//	hc32_pin_mode(DOWN_BQ_SDA_PIN,PIN_MODE_OUTPUT_PULLUP);
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		hc32_pin_mode(UP_BQ_SCL_PIN,PIN_MODE_OUTPUT_PULLUP);
//		hc32_pin_mode(UP_BQ_SDA_PIN,PIN_MODE_OUTPUT_PULLUP);
//	}
//	hc32_pin_mode(BQ_ALERT_PIN,PIN_MODE_INPUT_PULLDOWN);
//    hc32_pin_attach_irq(BQ_ALERT_PIN, PIN_IRQ_MODE_RISING, bq769x0_alert_callback);
//    hc32_pin_irq_enable(BQ_ALERT_PIN, PIN_IRQ_ENABLE);
//	bq_wake_ctrl();
//	uint8_t status = bq769xx_read_reg(BQ_DOWN, SYS_STAT);
//	bq769xx_write_reg(BQ_DOWN, SYS_STAT,status | 0x80);
//}

//static void bq_io_init(void){
//	hc32_pin_mode(BQ_WAKE_PIN,PIN_MODE_OUTPUT);
//	hc32_pin_mode(BQ_ALERT_PIN,PIN_MODE_INPUT_PULLDOWN);
//    hc32_pin_attach_irq(BQ_ALERT_PIN, PIN_IRQ_MODE_RISING, bq769x0_alert_callback);
//    hc32_pin_irq_enable(BQ_ALERT_PIN, PIN_IRQ_ENABLE);
//	hc32_pin_mode(PRE_CHARGE_PIN,PIN_MODE_OUTPUT);
//	hc32_pin_write(PRE_CHARGE_PIN,PIN_LOW);
//	hc32_pin_mode(CHARGE_LI_PIN,PIN_MODE_OUTPUT);
//	hc32_pin_write(CHARGE_LI_PIN,PIN_LOW);
//}

//static void bq769x0_read_gain(void){
//	uint8_t temp1 = 0;
//	uint8_t temp2 = 0;
//	temp1 = bq769xx_read_reg(BQ_DOWN,0x50);
//	temp2 = bq769xx_read_reg(BQ_DOWN,0x59);
//	bq_cali_info.bq_gain[BQ_DOWN] = temp2>>5|((temp1&0x0c)<<1);
//	bq_cali_info.bq_gain[BQ_DOWN] += 365;
//	
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		temp1 = 0;
//		temp2 = 0;
//		temp1 = bq769xx_read_reg(BQ_UP,0x50);
//		temp2 = bq769xx_read_reg(BQ_UP,0x59);
//		bq_cali_info.bq_gain[BQ_UP] = temp2>>5|((temp1&0x0c)<<1);
//		bq_cali_info.bq_gain[BQ_UP] += 365;
//	}
//	if(gain_flag==false)
//	{
//		gain_flag = true;
//		initial_gain_down = bq_cali_info.bq_gain[BQ_DOWN];
//		if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only)
//		{
//			initial_gain_up = bq_cali_info.bq_gain[BQ_UP];
//		}
//	}
//}

//static void bq769x0_read_offset(void){
//	uint8_t temp=0;
//	temp = bq769xx_read_reg(BQ_DOWN,0x51);
//	if(temp&0x80){
//		temp=~temp;
//		bq_cali_info.bq_offset[BQ_DOWN] = -(temp+1);
//	}else{
//		bq_cali_info.bq_offset[BQ_DOWN] = temp;
//	}
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		temp = 0;
//		temp = bq769xx_read_reg(BQ_UP,0x51);
//		if(temp&0x80){
//			temp=~temp;
//			bq_cali_info.bq_offset[BQ_UP] = -(temp+1);
//		}else{
//			bq_cali_info.bq_offset[BQ_UP] = temp;
//		}
//	}
//	if(offset_flag==false)
//	{
//		offset_flag = true;
//		initial_offset_down = bq_cali_info.bq_offset[BQ_DOWN];
//		if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only)
//		{
//			initial_offset_up = bq_cali_info.bq_offset[BQ_UP];
//		}
//	}
//}

//uint8_t bq769x0_read_vol(BQ_Side bqSide,uint16_t *volArray){
//	uint8_t res = 0;
//	uint8_t *pVolArray = (uint8_t *)volArray;
//	uint8_t read_reg_num = 5;//默认为920
//	if(bq_makeup_mode == bq76920_only){
//		read_reg_num = 5;
//	}else if(bq_makeup_mode == bq76930_only || bq_makeup_mode == bq76930_two){
//		read_reg_num = 10;
//	}else if(bq_makeup_mode == bq76940_only){
//		read_reg_num = 15;
//	}else if(bq_makeup_mode == bq76930_940){
//		if(bqSide == BQ_DOWN){//读低侧930
//			read_reg_num = 10;
//		}else if(bqSide == BQ_UP){//读高侧940
//			read_reg_num = 15;
//		}
//	}
//	if(bq769xx_read_regs(bqSide,0x0c,pVolArray,read_reg_num*2) == 0){
//		uint32_t tempVol = 0;
//		uint8_t i = 0;	
//		for(i=0;i<read_reg_num;i++){
//			tempVol = pVolArray[i*2]*256+pVolArray[i*2+1];
//			volArray[i] = tempVol* bq_cali_info.bq_gain[bqSide]/1000 + bq_cali_info.bq_offset[bqSide];
//		}
//		res = 0;
//	}else{
//		res = 1;
//	}
//	return res;
//}

//void bq769x0_read_rsense_vol(int *cur_mA){
//	int16_t curbuf = (bq769xx_read_reg(BQ_DOWN,CC_HI_BYTE)<<8) | bq769xx_read_reg(BQ_DOWN,CC_LO_BYTE);
//	*cur_mA = (int)((float)curbuf*8.44/CURDIVIDERRES);	
//	if((*cur_mA) != 0){
//	    if(abs(*cur_mA) < bq_cali_info.bq_cur_offset){
//	        bq_cali_info.bq_cur_offset = abs(*cur_mA);
//	    }
//	    if(*cur_mA > 0){
//	        *cur_mA -=  bq_cali_info.bq_cur_offset;
//	    }
//	    if(*cur_mA < 0){
//	        *cur_mA +=  bq_cali_info.bq_cur_offset;
//	    }
//	}
//}

//void bq769x0_set_OV_UV(uint16_t overVol,uint16_t underVol){
//	uint32_t ov_res[2] = {0};
//	uint32_t uv_res[2] = {0};
//	ov_res[BQ_DOWN] = (overVol  - bq_cali_info.bq_offset[BQ_DOWN]);
//	ov_res[BQ_DOWN] *= 1000L;
//	ov_res[BQ_DOWN] /= bq_cali_info.bq_gain[BQ_DOWN];
//	ov_res[BQ_UP]   = (overVol  - bq_cali_info.bq_offset[BQ_UP]);
//	ov_res[BQ_UP]   *= 1000L;
//	ov_res[BQ_UP]   /= bq_cali_info.bq_gain[BQ_UP];
//	uv_res[BQ_DOWN] = (underVol - bq_cali_info.bq_offset[BQ_DOWN]);
//	uv_res[BQ_DOWN] *= 1000L;
//	uv_res[BQ_DOWN] /= bq_cali_info.bq_gain[BQ_DOWN];
//	uv_res[BQ_UP]   = (underVol - bq_cali_info.bq_offset[BQ_UP]);
//	uv_res[BQ_UP]   *= 1000L;
//	uv_res[BQ_UP]   /= bq_cali_info.bq_gain[BQ_UP];
//	ov_res[BQ_DOWN] >>= 4;
//	ov_res[BQ_UP]   >>= 4;
//	uv_res[BQ_DOWN] >>= 4;
//	uv_res[BQ_UP]   >>= 4;
//	ov_res[BQ_DOWN] &= 0x00ff;
//	ov_res[BQ_UP]   &= 0x00ff;
//	uv_res[BQ_DOWN] &= 0x00ff;
//	uv_res[BQ_UP]   &= 0x00ff;
//	bq769xx_write_reg(BQ_DOWN,0x09,ov_res[BQ_DOWN]);
//	bq769xx_write_reg(BQ_DOWN,0x0A,uv_res[BQ_DOWN]);
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		bq769xx_write_reg(BQ_UP,0x09,ov_res[BQ_UP]);
//		bq769xx_write_reg(BQ_UP,0x0A,uv_res[BQ_UP]);
//	}
//}

//void bq769x0_set_OV_UV_Delay(uint8_t odelay,uint8_t udelay){
//	uint8_t uv_delay_table[4]={1,4,8,16};//s
//	uint8_t ov_delay_table[4]={1,2,4,8};//s
//	uint8_t i=0;
//	uint8_t uv_delay=0;
//	uint8_t ov_delay=0;
//	uint8_t temp=0;
//	for(i=0;i<4;i++){
//		if(odelay==ov_delay_table[i]){
//			ov_delay=i;
//			break;
//		}
//	}
//	for(i=0;i<4;i++){
//		if(udelay==uv_delay_table[i]){
//			uv_delay=i;
//			break;
//		}
//	}
//	temp=(uv_delay<<6)|(ov_delay<<4);
//	bq769xx_write_reg(BQ_DOWN,0x08,temp);
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		bq769xx_write_reg(BQ_UP,0x08,temp);
//	}
//}

//void bq769x0_set_OCD(uint16_t curVol,uint16_t delay){
//	uint8_t res=0;
//	uint8_t i=0;
//	uint8_t cur_class=0;
//	uint8_t delay_class=0;
//	uint8_t temp=0;
//	for(i=0;i<16;i++){
//		if(curVol==oc_cur_table[i]){
//			cur_class=i;
//			break;
//		}
//	}
//	for(i=0;i<8;i++){
//		if(delay==oc_delay_table[i]){
//			delay_class=i;
//			break;
//		}
//	}
//	temp=(delay_class<<4)|cur_class;
//	bq769xx_write_reg(BQ_DOWN,0x07,temp);
//	res=bq769xx_read_reg(BQ_DOWN,0x07);
//}

//void bq769x0_set_SCD(uint16_t curVol,uint16_t delay){
//	uint8_t res=0;
//	uint8_t i=0;
//	uint8_t cur_class=0;
//	uint8_t delay_class=0;
//	uint8_t temp=0;
//	for(i=0;i<8;i++){
//		if(curVol==sc_cur_table[i]){
//			cur_class=i;
//			break;
//		}
//	}
//	for(i=0;i<4;i++){
//		if(delay==sc_delay_table[i]){
//			delay_class=i;
//			break;
//		}
//	}
//	temp=(delay_class<<3)|cur_class;
//	temp|=0x80;
//	bq769xx_write_reg(BQ_DOWN,0x06,temp);
//	res=bq769xx_read_reg(BQ_DOWN,0x06);
//}

//void bq769x0_balance_ctrl(BQ_Side bqSide,uint32_t balCode){

//	if(bq_makeup_mode == bq76920_only){
//		bq769xx_write_reg(bqSide,0x01,balCode&0x1f);
//	}else if(bq_makeup_mode == bq76930_only || bq_makeup_mode == bq76930_two){	
//			bq769xx_write_reg(bqSide,0x01,balCode&0x1f);
//			bq769xx_write_reg(bqSide,0x02,(balCode >> 5)&0x1f);
//	}else if(bq_makeup_mode == bq76940_only){
//		bq769xx_write_reg(bqSide,0x01,balCode&0x1f);
//		bq769xx_write_reg(bqSide,0x02,(balCode >> 5)&0x1f);
//		bq769xx_write_reg(bqSide,0x03,(balCode >> 10)&0x1f);
//	}else if(bq_makeup_mode == bq76930_940){
//		if(bqSide == BQ_DOWN){//930在低侧
//			bq769xx_write_reg(bqSide,0x01,balCode&0x1f);
//			bq769xx_write_reg(bqSide,0x02,(balCode >> 5)&0x1f);
//		}else{//940在高侧
//			bq769xx_write_reg(bqSide,0x01,balCode&0x1f);
//			bq769xx_write_reg(bqSide,0x02,(balCode >> 5)&0x1f);
//			bq769xx_write_reg(bqSide,0x03,(balCode >> 10)&0x1f);
//		}
//	}
//}

//uint8_t bq769x0_chg_ctrl(uint8_t ctrlCode){
//	uint8_t temp=0;
//	temp=bq769xx_read_reg(BQ_DOWN,0x05);
//	if(ctrlCode==0){
//		temp &= 0xFE;
//	}else{
//		temp |= 0x01;
//	}
//	bq769xx_write_reg(BQ_DOWN,0x05,temp);
//	temp=bq769xx_read_reg(BQ_DOWN,0x05);
//	
//	return (bool)(temp & 0x01);
//}

//uint8_t bq769x0_dsg_ctrl(uint8_t ctrlCode){
//	if(bq_status.sys_reg.bits.SCD == 0){
//		uint8_t temp=0;	
//		temp=bq769xx_read_reg(BQ_DOWN,0x05);
//		if(ctrlCode==0){
//			temp &= 0xFD;
//		}else{
//			temp |= 0x02;
//		}	
//		bq769xx_write_reg(BQ_DOWN,0x05,temp);
//		temp=bq769xx_read_reg(BQ_DOWN,0x05);
//		
//		return (bool)(temp & 0x02);
//	}else{
//		return 0;
//	}
//}

//uint8_t pre_charge_ctrl(uint8_t ctrlCode){
//	if(ctrlCode == 1){
//		hc32_pin_write(PRE_CHARGE_PIN,PIN_HIGH);
//		pre_charge_state = 1;
//	}else{
//		hc32_pin_write(PRE_CHARGE_PIN,PIN_LOW);
//		pre_charge_state = 0;
//	}
//	return pre_charge_state;
//}

//uint8_t charge_li_ctrl(uint8_t ctrlCode){
//	if(ctrlCode == 1){
//		hc32_pin_write(CHARGE_LI_PIN,PIN_HIGH);
//		charge_li_state = 1;
//	}else{
//		hc32_pin_write(CHARGE_LI_PIN,PIN_LOW);
//		charge_li_state = 0;
//	}
//	return charge_li_state;
//}

//void bq769x0_update_status(void){
//	
//	BQ_SYS_CTRL_REG_STATUS bq_down_reg_status;
//	BQ_SYS_CTRL_REG_STATUS bq_up_reg_status;
//	bq_up_reg_status.ctrl2_reg.regByte = 0x00;
//	bq_up_reg_status.sys_reg.regByte = 0x00;
//	bq_down_reg_status.sys_reg.regByte = bq769xx_read_reg(BQ_DOWN,0x00);
//	bq769xx_write_reg(BQ_DOWN,0x00,bq_down_reg_status.sys_reg.regByte);
//	if(bq_makeup_mode == bq76930_940 || bq_makeup_mode == bq76930_two){//存在两个
//		bq_up_reg_status.sys_reg.regByte = bq769xx_read_reg(BQ_UP,0x00);
//		bq769xx_write_reg(BQ_UP,0x00,bq_up_reg_status.sys_reg.regByte);
//	}
//	bq_status.sys_reg.bits.CC_READY = bq_down_reg_status.sys_reg.bits.CC_READY;
//	bq_status.sys_reg.bits.OVRD_ALERT = bq_down_reg_status.sys_reg.bits.OVRD_ALERT;
//	bq_status.sys_reg.bits.DEVICE_XREADY = bq_down_reg_status.sys_reg.bits.DEVICE_XREADY;
//	bq_status.sys_reg.bits.OCD = bq_down_reg_status.sys_reg.bits.OCD;
//	bq_status.sys_reg.bits.SCD = bq_down_reg_status.sys_reg.bits.SCD;
//	bq_status.sys_reg.bits.OV = bq_down_reg_status.sys_reg.bits.OV | bq_up_reg_status.sys_reg.bits.OV;
//	bq_status.sys_reg.bits.UV = bq_down_reg_status.sys_reg.bits.UV | bq_up_reg_status.sys_reg.bits.UV;
//	bq_status.ctrl2_reg.regByte = bq769xx_read_reg(BQ_DOWN,0x05);
//	bq_status.ctrl2_reg.bits.PRE_MOS = pre_charge_state;
//	bq_status.ctrl2_reg.bits.CHG_LI = charge_li_state;
//}

//BQ_SYS_CTRL_REG_STATUS get_bq769x0_status(void){
//	return bq_status;
//}

//void bq769x0_reboot(void){
//	bq_wake_ctrl();
//}

//bool clear_BQbalance_state(void){
//	if(((bq769xx_read_reg(BQ_DOWN,0x01))!=0) &&((bq769xx_read_reg(BQ_DOWN,0x02))!=0) &&((bq769xx_read_reg(BQ_UP,0x01))!=0) &&((bq769xx_read_reg(BQ_UP,0x02))!=0))
//	{	
//		return true;
//	}
//	return false;
//}

//void bq769x0_init(void){	
//	bq_status.sys_reg.regByte = 0;
//	bq_status.ctrl2_reg.regByte = 0;
//	bq_cali_info.bq_cur_offset = 100;
//	bq_io_init();
//	bq_wake_ctrl();
//	memset((char *)&bq_cali_info,0,sizeof(Bq769x0CaliInfo));
//	bq_iic_index[BQ_DOWN] = drv_i2c_register(DOWN_BQ_SCL_PIN,DOWN_BQ_SDA_PIN,&bq_iic_bus[BQ_DOWN]);
//	while(bq_iic_index[BQ_DOWN] < 0){
//		printf("bq i2c bus register failed,up_index = %d,down_index = %d\n",bq_iic_index[BQ_DOWN],bq_iic_index[BQ_DOWN]);
//		Delay_ms(1000);
//	}
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		bq_iic_index[BQ_UP] = drv_i2c_register(UP_BQ_SCL_PIN,UP_BQ_SDA_PIN,&bq_iic_bus[BQ_UP]);
//		while(bq_iic_index[BQ_UP] < 0){
//			printf("bq i2c bus register failed,up_index = %d,down_index = %d\n",bq_iic_index[BQ_UP],bq_iic_index[BQ_UP]);
//			Delay_ms(1000);
//		}
//	}
//	bq769x0_dsg_ctrl(0x00);
//	bq769x0_chg_ctrl(0x00);
//	bq769x0_read_gain();
//	bq769x0_read_offset();
//	
////	printf("bq_cali_info.bq_gain[BQ_DOWN]=%d\n",bq_cali_info.bq_gain[BQ_DOWN]);
////	printf("bq_cali_info.bq_gain[BQ_UP]=%d\n",bq_cali_info.bq_gain[BQ_UP]);
////	printf("bq_cali_info.bq_offset[BQ_DOWN]=%d\n",bq_cali_info.bq_offset[BQ_DOWN]);
////	printf("bq_cali_info.bq_offset[BQ_UP]=%d\n",bq_cali_info.bq_offset[BQ_UP]);
//	
//	if(bq_cali_info.bq_gain[BQ_DOWN] == 365 || bq_cali_info.bq_offset[BQ_DOWN] == 0){
//		bq769x0_read_gain();
//		bq769x0_read_offset();
//		if(bq_cali_info.bq_gain[BQ_DOWN] == 365 || bq_cali_info.bq_offset[BQ_DOWN] == 0){
//			Soft_Reset();
//		}
//	}

//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		if(bq_cali_info.bq_gain[BQ_UP] == 365 || bq_cali_info.bq_offset[BQ_UP] == 0){
//			bq769x0_read_gain();
//			bq769x0_read_offset();
//			if(bq_cali_info.bq_gain[BQ_UP] == 365 || bq_cali_info.bq_offset[BQ_UP] == 0){
//				Soft_Reset();
//			}
//		}
//	}
//	
//	bq769xx_write_reg(BQ_DOWN, CC_CFG,0x19);
//	bq769xx_write_reg(BQ_DOWN, SYS_CTRL2,0x40);
//	bq769xx_write_reg(BQ_DOWN, SYS_STAT,0xFF);
//	
//	if(bq_makeup_mode == bq76920_only){
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//	}else if(bq_makeup_mode == bq76930_only){
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X02,0x00);
//	}else if(bq_makeup_mode == bq76930_two){	
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X02,0x00);
//		bq769xx_write_reg(BQ_UP, 0X01,0x00);
//		bq769xx_write_reg(BQ_UP, 0X02,0x00);
//	}else if(bq_makeup_mode == bq76940_only){
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X02,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X03,0x00);
//	}else if(bq_makeup_mode == bq76930_940){
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X02,0x00);
//		bq769xx_write_reg(BQ_UP, 0X01,0x00);
//		bq769xx_write_reg(BQ_UP, 0X02,0x00);
//		bq769xx_write_reg(BQ_UP, 0X03,0x00);
//	}
//	printf("bq init\n");
//}

//void bq769x0_reboot_init(void){	
//	bq_status.sys_reg.regByte = 0;
//	bq_status.ctrl2_reg.regByte = 0;
//	bq_cali_info.bq_cur_offset = 100;
//	bq_io_init();
//	bq_wake_ctrl();
//	memset((char *)&bq_cali_info,0,sizeof(Bq769x0CaliInfo));
//	bq_iic_index[BQ_DOWN] = drv_i2c_register(DOWN_BQ_SCL_PIN,DOWN_BQ_SDA_PIN,&bq_iic_bus[BQ_DOWN]);
//	while(bq_iic_index[BQ_DOWN] < 0){
//		printf("bq i2c bus register failed,up_index = %d,down_index = %d\n",bq_iic_index[BQ_DOWN],bq_iic_index[BQ_DOWN]);
//		Delay_ms(1000);
//	}
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		bq_iic_index[BQ_UP] = drv_i2c_register(UP_BQ_SCL_PIN,UP_BQ_SDA_PIN,&bq_iic_bus[BQ_UP]);
//		while(bq_iic_index[BQ_UP] < 0){
//			printf("bq i2c bus register failed,up_index = %d,down_index = %d\n",bq_iic_index[BQ_UP],bq_iic_index[BQ_UP]);
//			Delay_ms(1000);
//		}
//	}
//	bq769x0_dsg_ctrl(0x00);
//	bq769x0_chg_ctrl(0x00);
//	bq769x0_read_gain();
//	bq769x0_read_offset();
//	
//	if(bq_cali_info.bq_gain[BQ_DOWN] == 365 || bq_cali_info.bq_offset[BQ_DOWN] == 0){
//		bq_cali_info.bq_gain[BQ_DOWN] = initial_gain_down;
//		bq_cali_info.bq_offset[BQ_DOWN] = initial_offset_down;
//	}
//	
//	if(bq_makeup_mode != bq76920_only && bq_makeup_mode != bq76930_only && bq_makeup_mode != bq76940_only){
//		if(bq_cali_info.bq_gain[BQ_UP] == 365 || bq_cali_info.bq_offset[BQ_UP] == 0){
//			bq_cali_info.bq_gain[BQ_UP] = initial_gain_up;
//			bq_cali_info.bq_offset[BQ_UP] = initial_gain_up;
//		}
//	}

//	bq769xx_write_reg(BQ_DOWN, CC_CFG,0x19);
//	bq769xx_write_reg(BQ_DOWN, SYS_CTRL2,0x40);
//	bq769xx_write_reg(BQ_DOWN, SYS_STAT,0xFF);
//	
//	if(bq_makeup_mode == bq76920_only){
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//	}else if(bq_makeup_mode == bq76930_only){
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X02,0x00);
//	}else if(bq_makeup_mode == bq76930_two){	
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X02,0x00);
//		bq769xx_write_reg(BQ_UP, 0X01,0x00);
//		bq769xx_write_reg(BQ_UP, 0X02,0x00);
//	}else if(bq_makeup_mode == bq76940_only){
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X02,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X03,0x00);
//	}else if(bq_makeup_mode == bq76930_940){
//		bq769xx_write_reg(BQ_DOWN, 0X01,0x00);
//		bq769xx_write_reg(BQ_DOWN, 0X02,0x00);
//		bq769xx_write_reg(BQ_UP, 0X01,0x00);
//		bq769xx_write_reg(BQ_UP, 0X02,0x00);
//		bq769xx_write_reg(BQ_UP, 0X03,0x00);
//	}
//	printf("bq init\n");
//}
